<template>
   <a-layout style="min-height: 100vh">
      <a-layout-sider v-model:collapsed="collapsed" collapsible>
         <div class="logo"></div>

         <a-menu v-model:selectedKeys="selectedKeys" theme="dark" mode="inline" @click="handleMenuClick">
            <a-menu-item key="/home/styleHome">
               <!-- <pie-chart-outlined /> -->
               <home-outlined />
               <span>系统首页</span>
            </a-menu-item>


            <a-sub-menu key="sub1">
               <template #title>
                  <span>
                     <user-outlined />
                     <span>管理页</span>
                  </span>
               </template>
               <a-menu-item key="/home/userManage">用户中心</a-menu-item>
            </a-sub-menu>

            <a-menu-item key="/home/file">
               <file-outlined />
               <span>File</span>
            </a-menu-item>

         </a-menu>
      </a-layout-sider>

      <!-- 主体 -->
      <a-layout>
         <a-layout-header style="background: #fff; padding: 0">
            <Header :userInfo = "useUserStore1.userInfoZhen"></Header>
         </a-layout-header>
         <a-layout-content style="margin: 0 16px">
            <router-view></router-view>
         </a-layout-content>
         <a-layout-footer style="text-align: center">
            用户中心平台2024
         </a-layout-footer>
      </a-layout>
   </a-layout>
</template>

<script lang="ts" setup>
import {
   HomeOutlined,
   UserOutlined,
   FileOutlined,
} from '@ant-design/icons-vue';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute()
const router = useRouter()
const collapsed = ref<boolean>(false);
const selectedKeys = ref<string[]>([route.path]);

import { message } from 'ant-design-vue';
const handleMenuClick = ({ key }: any) => {

   //一些页面需要权限

   if (key == '/home/userManage' && useUserStore1.userInfoZhen.role == 0) {
      //如果不是管理员无法进入
      message.error('不是管理员，没有权限');
   } else {
      router.push({
         path: key
      });
   }


};


//登录后查询个人信息
import { useUserStore } from '../store/userStore'
const useUserStore1 = useUserStore()
onMounted(async () => {
   await useUserStore1.userInfoM()
   if (route.path == '/home/userManage' && useUserStore1.userInfoZhen.role == 0) {
      message.error('警告！！！！');
      router.replace({
         path: '/404'
      } )

   }
})


</script>

<style scoped>
#components-layout-demo-side .logo {
   height: 32px;
   margin: 16px;
   background: rgba(255, 255, 255, 0.3);
}

.site-layout .site-layout-background {
   background: #fff;
}

[data-theme='dark'] .site-layout .site-layout-background {
   background: #141414;
}
</style>